<?php
if(isset($_COOKIE['username']))
{
	include 'mysql_connect.php';	
	$username=$_COOKIE['username'];	
	$uid=mysql_query("SELECT `uid` FROM `member` WHERE `username`='$username' ");	
	$uid=mysql_fetch_array($uid);
	$uid=$uid['uid'];	
	setcookie("UID",$uid,(time()+3600));	
	header("location:user_zone.php?uid=$uid");
}

if(isset($_GET['mess']))
{	
	setcookie("username",$username,(time()-3600));
}
$username=$_POST['username'];
$password=md5($_POST['password']);
$submit=$_POST['submit'];

if($submit=='登陆')
{	
	require_once 'mysql_connect.php';
	
	if(!mysql_query(" SELECT `username` FROM `member` WHERE `username`='$username' "))
	{
		$message="<a href=register.php>用户名<font color=red>$username</font>不存在</a><br />";
		header("location:show.php?show=$message");
	}
	else
	{	
		$mysql_pw=mysql_query(" SELECT `password` FROM `member` WHERE `username`='$username'");
		$mysql_pw=mysql_fetch_array($mysql_pw);

		if($mysql_pw['password']==$password)
		{
			$infor=mysql_query(" SELECT `uid` FROM `member` WHERE `username`='$username' ");
			$infor=mysql_fetch_array($infor);
			$uid=$infor['uid'];
			
			setcookie("uid",$uid,(time()+604800));
			setcookie("username",$username,(time()+604800));
			
			header("location:user_zone.php?uid=$uid");		
		}
		else
		{
			$message="<a href=login.php><font color=red>密码错误</font></a><br />";
			header("location:show.php?show=$message");
		}
	}

}
elseif($submit=='注册')
{
	header("location:register.php");
}
elseif($submit=='忘记密码')
{
	header("location:forgot.php");
}

?>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>用户登陆</title>
</head>

<body>
	<hr /><br />
	<form action="login.php" method="post">
	<table align="center" border="1" >
		<tr>
			<td width="74" align="right">用户名：</td>
			<td width="245" align="left"><input type="text" name="username" maxlength="25" size="25"> </td>
		</tr>
		<tr>
		<td align="right">密&nbsp;&nbsp;&nbsp;&nbsp;码：</td>
			<td align="left"><input type="password" name="password" size="27" maxlength="32"></td>
		</tr>
			<tr align="center"><td colspan="2">
				<input type="submit" name="submit" value="登陆">
				<input type="submit" name="submit" value="注册">
				<input type="submit" name="submit" value="忘记密码">
			</td>
		</tr>		
	</table>
	</form>
</body>
</html>